//滚动栏数据
var scrollbarVue=new Vue({
	el:"#scrollbar",
	data:{
		list:[]
	}
});
var noticeBoardVue=new Vue({
	el:"#notice-board",
	data:{
		currentDateSumDealMoney:0,
		currentMonthSumDealMoney:0,
		currentYearSumDealMoney:0,
		
		currentDateSumOrderQuantity:0,
		currentMonthSumOrderQuantity:0,
		currentYearSumOrderQuantity:0,
		
		
		
		tweenedCurrentDateSumDealMoney:0,
		tweenedCurrentMonthSumDealMoney:0,
		tweenedCurrentYearSumDealMoney:0,
		
		tweenedCurrentDateSumOrderQuantity:0,
		tweenedCurrentMonthSumOrderQuantity:0,
		tweenedCurrentYearSumOrderQuantity:0,
		
		
		show:true
	},
	computed: {
        animatedCurrentDateSumDealMoney: function() {
            return this.numFormat(this.tweenedCurrentDateSumDealMoney.toFixed(0));
        },
        animatedCurrentMonthSumDealMoney: function() {
            return this.numFormat(this.tweenedCurrentMonthSumDealMoney.toFixed(0));
        },
        animatedCurrentYearSumDealMoney: function() {
            return this.numFormat(this.tweenedCurrentYearSumDealMoney.toFixed(0));
        },
        
        animatedCurrentDateSumOrderQuantity: function() {
            return this.numFormat(this.tweenedCurrentDateSumOrderQuantity.toFixed(0));
        },
        animatedCurrentMonthSumOrderQuantity: function() {
            return this.numFormat(this.tweenedCurrentMonthSumOrderQuantity.toFixed(0));
        },
        animatedCurrentYearSumOrderQuantity: function() {
            return this.numFormat(this.tweenedCurrentYearSumOrderQuantity.toFixed(0));
        },
    },
    watch: {
        currentDateSumDealMoney: function(newValue) {
            TweenLite.to(this.$data, 2, { tweenedCurrentDateSumDealMoney: newValue });
        },
        currentMonthSumDealMoney: function(newValue) {
            TweenLite.to(this.$data, 2, { tweenedCurrentMonthSumDealMoney: newValue });
        },
        currentYearSumDealMoney: function(newValue) {
            TweenLite.to(this.$data, 2, { tweenedCurrentYearSumDealMoney: newValue });
        },
        
        currentDateSumOrderQuantity: function(newValue) {
            TweenLite.to(this.$data, 1, { tweenedCurrentDateSumOrderQuantity: newValue });
        },
        currentMonthSumOrderQuantity: function(newValue) {
            TweenLite.to(this.$data, 1, { tweenedCurrentMonthSumOrderQuantity: newValue });
        },
        currentYearSumOrderQuantity: function(newValue) {
            TweenLite.to(this.$data, 1, { tweenedCurrentYearSumOrderQuantity: newValue });
        }
    },
	methods:{
    	numFormat:function(num){
    		var numStr=String(num);
			var newNumStr=numStr;
			if(numStr.length>3){
				var numStr=numStr.split("").reverse().join("");
				var newNumStr=numStr[0];
			
				for(var i=1;i<numStr.length;i++){
					if(i%3==0){
						newNumStr+=","+numStr[i];
					}else{
						newNumStr+=numStr[i];
					}
				}
				newNumStr=newNumStr.split("").reverse().join("");
			}
			
			return newNumStr;
		}
    }
});


const backgroundColor='#45415a';


var currentDateData={};
var currentMonthData={};
var orderInfo=[];
//单位:秒

//滚动栏更新时间
const scrollTime=4;

//通知栏更新时间
const requestTimeInterval=30;

initNoticeBoard();
setVueDataTimer();

initChart();




function initChart(){
	var directory="/tlwork/Public/Home/data/";
	
	//活跃B端店铺数据
	var leftTopPromise=ajaxRequestPromise('index.php?s=/Home/Index/shopsales'); 

	//活跃频道数据
	var leftBottomPromise=ajaxRequestPromise(directory+"left-bottom.txt");

	// 政采交易金额
	var rightTopPromise=ajaxRequestPromise(directory+"right-top.txt");

	// 平台用户结构
	var rightBottomPromise=ajaxRequestPromise(directory+"right-bottom.txt");

	// 中国地图
	var chinaMap=ajaxRequestPromise('index.php?s=/Home/Index/map');

	var p = Promise.all([leftTopPromise,leftBottomPromise,rightTopPromise,rightBottomPromise,chinaMap]);
	p.then(function(list) {
	    //console.log(list);
	    
	    createLeftTopChart(list[0]);
	    createleftBottomChart(list[1]);
	    createRightTopChart(list[2]);
	    createRightBottomChart(list[3]);



	    //去除小数点
	    var createChinaMapData=list[4];
	    for(var i=0;i<createChinaMapData.length;i++){
	    	createChinaMapData[i].value=parseInt(createChinaMapData[i].value);
	    }
	    createChinaMapChart(createChinaMapData);
	});
	
}



//实时通知栏
function initNoticeBoard(){
	/*var directory="/tlwork/Public/Home/data/";
	
	//今天的当月1号0:0:0到当月当日减1天11:59:59 （如果是1号就为0）
	//当月 比如1到13号的"sumDealMoney":"交易金额","sumOrderQuantity":"订单量"
	var dateData=ajaxRequestPromise(directory+"dateData.txt");
	
	//本年 比如1月1号到4月底
	//今天的1月1号的0:0:0到当月1号-1天的11:59:59 （如果是1月就为0）
	var monthData=ajaxRequestPromise(directory+"monthData.txt");

	var p = Promise.all([dateData,monthData]);
	p.then(function(list) {
	    //console.log(list);
	    
	    initCurrentDateData(list[0]);
	    initCurrentMonthData(list[1]);
	    
	    initScrollbarVueData();
		setNoticeBoardVueData();

	});
	
	*/
	

	ajaxRequestPromise('index.php?s=/Home/Index/monthOrder').then(function(data){

		//当月=currentDateData+当日
		// 例如5月13日，5月1日0:0；0到5月12日23:59:59
		var tempCurrentDateData=data.currentDateData;
		tempCurrentDateData.sumDealMoney=parseInt(tempCurrentDateData.sumDealMoney);
		tempCurrentDateData.sumOrderQuantity=parseInt(tempCurrentDateData.sumOrderQuantity);
		currentDateData=tempCurrentDateData;

		//本年=当月+currentMonthData
		// 例如5月13日，1月1日0:0；0到4月30日（5月1日的前一天）23:59:59


		var tempCurrentMonthData=data.currentMonthData;
		tempCurrentMonthData.sumDealMoney=parseInt(tempCurrentMonthData.sumDealMoney);
		tempCurrentMonthData.sumOrderQuantity=parseInt(tempCurrentMonthData.sumOrderQuantity);
		currentMonthData=tempCurrentMonthData;
		initScrollbarVueData();
		setNoticeBoardVueData();
	})
    
    
	
}


//时间范围(startTimeStamp,endTimeStamp]
function searchTimeStampRangeData(startTimeStamp,endTimeStamp){
	var dataSource=[];
	
	//根据时间范围获得最新数据
	// var data=ajaxRequestPromise();
	// [{"storeName":"河北店铺","totalMoney":"10014","createTime":"18:58:07"}],

	$.ajax({
		type:"get",
		url:'http://120.77.0.127/tlwork/index.php?s=/Home/Index/realtime&start='+startTimeStamp+'&end='+endTimeStamp,
		async:false,
		success:function(data){
			var dataJson;
			if(typeof data=="object"){
				dataJson=data;
			}else if(typeof data == "string"){
				data=data.replace(/,\s*]/g,']');
				dataJson=JSON.parse(data);
			}
			
			dataSource=dataJson;
			//callbackMethodReference(dataJson);
		}
	});

	return dataSource;
}

function initScrollbarVueData(){

	// var initData=[];
	
	//@获得最近的两条数据
	
	//开始时最新两条订单
	// var initData=ajaxRequestPromise('{:U("Index/realOrder")}');
	// console.log(initData)
	// [{"storeName":"河北店铺","totalMoney":"10014","createTime":"18:58:07"}],
	
	ajaxRequestPromise('index.php?s=/Home/Index/realOrder').then(function(data){
		scrollbarVue.list=data;
	})
	/*$.ajax({
		type:"get",
		url:'http://120.77.0.127/tlwork/index.php?s=/Home/Index/realOrder',
		async:true,
		success:function(data){
			var dataJson;
			if(typeof data=="object"){
				dataJson=data;
			}else if(typeof data == "string"){
				data=data.replace(/,\s*]/g,']');
				dataJson=JSON.parse(data);
			}
			
			scrollbarVue.list=dataJson;
			//callbackMethodReference(dataJson);
		}
	});*/

	
}

function getCurrentDateSumDealMoney(){
	var currentDateSumDealMoney=0;
	
	$.ajax({
		type:"get",
		url:'http://120.77.0.127/tlwork/index.php?s=/Home/Index/dataOrderMoney',
		async:false,
		success:function(data){
			var dataJson;
			if(typeof data=="object"){
				dataJson=data;
			}else if(typeof data == "string"){
				data=data.replace(/,\s*]/g,']');
				dataJson=JSON.parse(data);
			}
			
			currentDateSumDealMoney=dataJson;
			//callbackMethodReference(dataJson);
		}
	});
	//@获得当日实时订单交易额
	/*ajaxRequestPromise('http://120.77.0.127/tlwork/index.php?s=/Home/Index/dataOrder').then(function(data){
		return data;
	})*/
	
	return currentDateSumDealMoney;
}

function getCurrentDateSumOrderQuantity(){

	var currentDateSumOrderQuantity=0;
	
	//获得当日实时订单数量
	$.ajax({
		type:"get",
		url:'http://120.77.0.127/tlwork/index.php?s=/Home/Index/dataOrderNumber',
		async:false,
		success:function(data){
			var dataJson;
			if(typeof data=="object"){
				dataJson=data;
			}else if(typeof data == "string"){
				data=data.replace(/,\s*]/g,']');
				dataJson=JSON.parse(data);
			}
			
			currentDateSumOrderQuantity=dataJson;
			//callbackMethodReference(dataJson);
		}
	});
	
	return currentDateSumOrderQuantity;
}







